import 'dart:collection';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
import '../models/basebean.dart';
import '../models/company.dart';
import '../models/financial_summary.dart';
import '../models/report_data.dart';
import '../models/services_data.dart';
import '../models/user.dart';
import '../models/user_company.dart';
part 'api_client.g.dart';


// @RestApi(baseUrl: "https://fc.hongfund.com:8602/",parser: kIsWeb ? Parser.JsonSerializable : Parser.FlutterCompute)
@RestApi(baseUrl: "https://fc.hongfund.com:8602/")
abstract class ApiClient {
  factory ApiClient(Dio dio, {String baseUrl}) = _ApiClient;

  static late ApiClient instance;

  static void initialize(Dio dio) {
    instance = ApiClient(dio);
  }

  //用户登录接口
  @POST("api/app/user/login")
  Future<BaseBean<User>> login(@Field("phone") String phone, @Field("code") String code);

  @GET("api/app/user/find")
  Future<BaseBean<User>> getUserInfo(@Query("userId") String userId);

  //用户登录接口
  @POST("api/app/user/send/code")
  Future<BaseBean<String>> sendCode(@Field("phone") String phone);

  @GET("api/tax/report/data/form/year")
  Future<BaseBean<Map<String,dynamic>>> homeDateYear(@Query("taxCode") String taxCode, @Query("year") String year);

  //当前季度数据
  @GET("api/tax/report/data/form/quarter")
  Future<BaseBean<Map<String,dynamic>>> homeDateQuarter(@Query("taxCode") String taxCode, @Query("startPeriod") String startPeriod,@Query("endPeriod") String endPeriod);



  @POST("api/app/company/save")
  Future<BaseBean<AppCompanyDto>> companySave(@Body() LinkedHashMap<String, dynamic> formData);

  @GET("api/tax/report/data/form/year")
  Future<BaseBean<Map<String,dynamic>>> getFinancialSummary(@Query("taxCode") String taxCode,@Query("year") String year);

  // New API method for report data
  // @GET("/reports/data")
  // Future<ReportData> getReportData(@Query("year") int year);
  @GET("api/app/company/find/list")
  Future<BaseBean<CompanyData>> getCompanyList(@Query("userId") String userId, @Query("page") int page, @Query("size") int size);

  @DELETE("api/app/company/delete")
  Future<BaseBean<String?>> getCompanyDelete(@Query("id") String id);

  @POST("api/app/user/switch/company")
  Future<BaseBean<String?>> getCompanySwitch(@Field("id") String id, @Field("companyId") String companyId);


  @GET("api/app/company/find/service")
  Future<BaseBean<List<ServicesBean>?>> findService(@Query("id") String id, @Query("companyId") String companyId);



  @POST("api/app/orders/create")
  Future<BaseBean<WxPayBean?>> serviceOrdersCreate(@Body() LinkedHashMap<String, dynamic> formData);
  // userId   companyId companyName serviceId serviceName amount  tradeType:APP


  @POST("api/app/orders/find")
  Future<BaseBean<OrderData?>> ordersList(@Field("userId") String id);
//, @Query("page") int page, @Query("size") int size



  // 利润表
  @GET("api/tax/report/data/form/income")
  Future<BaseBean<List<Map<String,dynamic>>>> getReportformIncome(@Query("taxCode") String taxCode, @Query("startPeriod") String startPeriod, @Query("endPeriod") String endPeriod  );



  //home 资产负债表（type 资产｜负债）
  @GET("api/tax/report/data/form/balance/sheet")
  Future<BaseBean<List<Map<String,dynamic>>>> getReportformBalanceSheet(@Query("taxCode") String taxCode,
      @Query("type") String type,
      @Query("startPeriod") String startPeriod, @Query("endPeriod") String endPeriod  );


  //home 主页趋势图
  @GET("api/tax/report/data/form/echarts")
  Future<BaseBean<Map<String,dynamic>>> getReportformTecharts(@Query("taxCode") String taxCode, @Query("year") String year);


  //纳税表
  @GET("api/tax/report/data/form/tax")
  Future<BaseBean<Map<String,dynamic>>> getReportformTax(@Query("taxCode") String taxCode, @Query("startPeriod") String startPeriod, @Query("endPeriod") String endPeriod);


  //获取聊天列表
  // @GET("api/ai/chat/list")
  // Future<BaseBean<Map<String,dynamic>>> getAiChatList(@Query("phone") String phone,
  //     @Query("aiType") String aiType, @Query("page") int page, @Query("size") int size);
  @GET("api/ai/chat/list")
  Future<BaseBean<Map<String,dynamic>>> getAiChatList(@Queries() Map<String, dynamic> formData);


  //. 收藏或取消收藏接⼝
  @POST("api/ai/chat/like")
  Future<BaseBean<Map<String,dynamic>>> aiChatLike(@Field("id") String id);



  //查询单条对话接⼝
  @GET("api/ai/chat/one")
  Future<BaseBean<Map<String,dynamic>>> aiChatOne(@Query("id") String id);



  //查询⽂件状态接⼝⼝
  @GET("/api/ai/chat/check/file")
  Future<BaseBean<Map<String,dynamic>>> aiChatCheckFile(@Query("fileId") String fileId);



  //上传文件的接口
  @MultiPart()
  @POST("/api/ai/chat/upload")
  Future<BaseBean<Map<String,dynamic>>> aiChatUpload(@Part(contentType:'application/json') File file);




  //获取登录验证信息
  @GET("/api/rpa/cookie/task/info")
  Future<BaseBean<Map<String,dynamic>>> cookietaskInfo(@Queries() Map<String, dynamic> formData);


  //登录验证发送短信
  @POST("/api/rpa/cookie/task/save")
  Future<BaseBean<Map<String,dynamic>>> cookieTaskSave(@Body()  Map<String, dynamic> formData);



  //登录验证上送短信
  @POST("/api/rpa/cookie/task/sms/code")
  Future<BaseBean<Map<String,dynamic>>> cookieTaskSmsCode(@Body()  Map<String, dynamic> formData);



  //登录验证上送短信
  @GET("/api/app/orders/consult/enable")
  Future<BaseBean<Map<String,dynamic>>> ordersConsultEnable(@Queries()  Map<String, dynamic> formData);




}

Map<String, dynamic> mapFromStringDynamic(Map<String, dynamic> json) {
  return json.map((key, value) => MapEntry(key, value.toString()));
}

Map<String, dynamic> fromJson(Map<String, dynamic> json) {
  return json.map((key, value) => MapEntry(key, value));
}

extension LinkedHashMapExtension on Map<String, dynamic> {
  Map<String, dynamic> toJson() {
    return Map<String, dynamic>.from(this);
  }
}